Extract words from sentence(s) using TSQL(SQL SERVER 2005) [ SET BASED SOLUTION]

Posted by Newbie on Stack Overflow See other posts from Stack Overflow or by Newbie
Published on 2010-06-17T08:09:35Z Indexed on 2010/06/17 8:13 UTC
Read the original article Hit count: 660

Filed under:

I have the following input.

INPUT:

TableA
ID       Sentences
---         ----------

1            I am a student

2            Have a nice time guys!

What I need to do is to extract the words from the sentence(s)

and insert each individual word in another table

OUTPUT:

SentenceID  WordOccurance   Word
----------  ------------    -----

1                1             I
1                2             am
1                3             a
1                4            student
2                1            Have
2                2            a
2                3            nice
2                4            time
2                5            guys!

I am using SQL SERVER 2005.

I am looking for a set based solution.

Thanks

© Stack Overflow or respective owner

Related posts about sql-server-2005